<?php
/**
 * Description of Acl
 *
 * @author Gowork
 */
class Application_Model_Acl {
    
    protected $_oFrontController = null;
    protected $_aResources = null;
    
    
    public function __construct() {
        $this->_oFrontController = Zend_Controller_Front::getInstance();
    }
    
    /**
     * 
     * @return \Application_Model_Acl_ResourceCollection
     */
    public function getActualResources() {
        
        $oCollection = new Application_Model_Acl_ResourceCollection();
        
        $aModulesPaths = $this->_oFrontController->getControllerDirectory();
        $aActionList = array();
        
        foreach($aModulesPaths as $sModuleName => $sModulePath) {
            if($sModuleName != 'default') {
                
                $oControllerFiles = new DirectoryIterator($sModulePath);
                
                foreach($oControllerFiles as $oControllerFile) {
                    
                    if(!$oControllerFile->isFile()) {
                        continue;
                    }
                    
                    require_once($sModulePath.'/'.$oControllerFile->getFilename());
                    
                    $oInfo = new Zend_Reflection_File($sModulePath.'/'.$oControllerFile->getFilename());
                    
                    $aActions = get_class_methods($oInfo->getClass()->name);
                    
                    foreach ($aActions as $sAction) {
                        if(strstr($sAction, 'Action')!=false) {
                            $sController = substr($oInfo->getClass()->name, strlen($sModuleName)+1);
//                            $aActionList[] = array(
//                                'module'=> strtolower($sModuleName), 
//                                'controller'=> strtolower(substr( $sController , 0,strpos($sController,"Controller"))),
//                                'action'=> strtolower(substr($sAction,0,strpos($sAction,"Action"))) 
//                            );
                            $oCollection->add(array(
                                'module'=> strtolower($sModuleName),
                                'controller'=> strtolower(substr( $sController , 0,strpos($sController,"Controller"))),
                                'action'=> strtolower(substr($sAction,0,strpos($sAction,"Action"))) 
                            ));
	                }
                    }
                    
                }
                
            }
        }
        
        //return $aActionList;
        return $oCollection;
        
    }
    
    
    
}

?>
